home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-04
/
prolog_2.zip
/
PUZZLES.ZIP
/
VIENNEAU.PRO
< prev
next >
Wrap
Text File
|
1986-07-09
|
8KB
|
207 lines
/*
This program solves the following logic puzzle.
Klare, Lemon, Morton, and Nelson are all women who love their work. They work
as a dress designer, florist, gardener, and symphony conductor. Each woman has
one and only only job, and each job is filled by one and only one woman. From
the clues below, match up each woman's name with her type of work.
1. Klare is violently allergic to most plants.
2. Lemon and the florist are roommates.
3. Morton and Lemon like only rock music.
4. The gardener, the dress designer, and Nelson are strangers.
This problem was an assignment in some AI class conducted at Syracuse
University in the spring of 1986. (I didn't take the class.)
TO RUN, type
start.
*/
/* Program Author:
Robert L. Vienneau
724 North James St
Rome, NY 13440
315-336-5417
*/
/* The general approach is to write down everything I know and let the
computer draw the conclusions. Question: would something like this be possible
if I hadn't first solve the puzzle? It seems I first need to know what aspects
of my knowledge of music, strangers, roommates, and loving-work is relevant.
Then I have to know in what order to write down my knowledge. Both are
crucial.
What does this say about the prospects for using this program as an exemplar
for AI (considered as at attempt to build intelligent machines and expand our
knowledge of workings of the human mind, not as productive of neat programming
practices such as those involved in expert systems)?
Of course, in a sense, I have not specified any of my knowledge to the
computer. The computer only "knows" syntactical rules for manipulating strings
of symbols. The meaning of these symbols, their semantics/pragmatics, how they
point to things in the world cannot be specified in a program. How we assign
meaning to symbols is a deep philosophical problem. Those interested in more
should read anything on Ludwig Wittegenstein (early or late periods). */
/* Some stuff to help the user: */
help :- start.
start :-
nl, print( 'Klare, Lemon, Morton, and Nelson are all women who love their' ),
nl, print( 'work. They work as a dress designer, florist, gardener, and' ),
nl, print( 'symphony conductor. Each woman has one and only only job, and' ),
nl, print( 'each job is filled by one and only one woman. From the clues' ),
nl, print( 'below, match up each woman\'s name with her type of work.' ),
nl,
nl, print( ' 1. Klare is violently allergic to most plants.' ),
nl,
nl, print( ' 2. Lemon and the florist are roommates.' ),
nl,
nl, print( ' 3. Morton and Lemon like only rock music.' ),
nl,
nl, print( ' 4. The gardener, the dress designer, and Nelson are' ),
nl, print( ' strangers.' ),
nl,
nl,
nl, print( 'To find the solution to this problem, type such things as' ),
nl,
nl, print( ' job( \'symphony conductor\', nelson ).' ),
nl,
nl, print( 'Note types of work are first, enclosed in single quotes, and' ),
nl, print( 'uncapitalized; names are second and uncapitalized.' ).
/* Each woman has one and only one job. Each job is filled by
one and only one woman. (I believe if I coded these in all
their generality I'd have infinite loops/recursion.) */
/* I couldn't get the supplied not function to work so I wrote
my own (call ed knot) */
job( 'florist', X ) :- woman( X ),
candidate( 'florist', X ),
knot( job( 'dress designer', X )),
knot( job( 'gardener', X )),
knot( job( 'symphony conductor', X )).
job( 'gardener', X ) :- woman( X ),
candidate( 'gardener', X ),
knot( job( 'dress designer', X )),
knot( candidate( 'florist', X )),
knot( job( 'symphony conductor', X )).
job( 'dress designer', X) :- woman( X ),
candidate( 'dress designer', X ),
knot( candidate( 'florist', X )),
knot( candidate( 'gardener', X )),
knot( job( 'symphony conductor', X )).
job( 'symphony conductor', X ) :- woman(X),
candidate( 'symphony conductor', X ),
knot( candidate( 'dress designer', X )),
knot( candidate( 'florist', X )),
knot( candidate( 'gardener', X )).
/* Some general facts about loving jobs, allegories, strangers,
roommates, rock an roll, etc. */
candidate( X, Y ) :- work( X ), woman( Y ),
firstcondition( X, Y ),
secondcondition( X, Y ),
thirdcondition( X, Y ),
fourthcondition( X, Y ),
fifthcondition( X, Y ).
/* Those who love jobs as florists or gardeners are not
allergic to most plants */
firstcondition( 'dress designer', Y ) :- woman( Y ).
firstcondition( 'florist', Y) :- woman( Y ), knot( allergic( Y ) ).
firstcondition( 'gardener', Y) :- woman( Y ), knot( allergic( Y ) ).
firstcondition( 'symphony conductor', Y ) :- woman( Y ).
/* Those who love a job as a conductor do not like only rock */
secondcondition( 'dress designer', Y ) :- woman( Y ).
secondcondition( 'florist', Y ) :- woman( Y ).
secondcondition( 'gardener', Y ) :- woman( Y ).
secondcondition( 'symphony conductor', Y ) :- woman( Y ),
knot( likesonlyrock( Y )).
/* In this puzzle, a person does not hold the same job
as her roommate */
thirdcondition( X, Y ) :- work( X ), woman( Y ),
knot( roommate( X, Y )).
/* In this puzzle, a person does not hold the same job
as people she's strangers with */
fourthcondition( X, Y ) :- work( X ), woman( Y ),
knot( stranger1( X, Y )).
/* The following code performs the following line of reasoning:
One can show that lemon is either the dress designer
or the gardener. nelson is strangers with both the
dress designer and the gardener. Hence nelson and
lemon are strangers. People are not strangers with
their roommates; lemon's roomate is the florist.
Hence nelson is not a candidate for the florist's
job. */
fifthcondition( 'dress designer', X ) :- woman( X ).
fifthcondition( 'gardener', X ) :- woman( X ).
fifthcondition( 'symphony conductor', X ) :- woman( X ).
/* there is some bug I dont fully understand. It involves the eitherjob
function below calling candidate which calls fifthcondition which
calls eitherjob again. The next line is a patch that
takes care of it. More analysis should be done, though. */
fifthcondition( 'florist', morton ).
fifthcondition( 'florist', Y ) :- woman( Y ),
knot(roommate('florist', Z)),
knot(stranger3(Z, Y)).
stranger3(X,Y) :- woman(X), woman(Y),
eitherjob('dress designer', 'gardener', X),
stranger1('dress designer', Y),
stranger1('gardener', Y).
eitherjob('dress designer', 'gardener', X) :- woman(X),
knot(candidate('florist', X)),
knot(candidate('symphony conductor', X)).
/* The specification of the puzzle in prolog follows */
allergic( klare ).
roommate( 'florist', lemon ).
likesonlyrock( morton ).
likesonlyrock( lemon ).
stranger1( 'gardener', nelson).
stranger1( 'dress designer', nelson).
woman( klare ).
woman( lemon ).
woman( morton ).
woman( nelson ).
work( 'dress designer' ).
work( 'florist' ).
work( 'gardener' ).
work( 'symphony conductor' ).
/* some useful functions */
knot(P) :- P, !, fail.
knot(P).